package com.manor.main.adapter;

import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.resource.bitmap.CenterCrop;
import com.bumptech.glide.load.resource.bitmap.RoundedCorners;
import com.bumptech.glide.request.RequestOptions;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.module.LoadMoreModule;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.manor.common.custom.DrawableTextView;
import com.manor.common.utils.DpUtil;
import com.manor.common.utils.StringUtil;
import com.manor.main.R;
import com.manor.main.bean.BottomSameCityBean;

import java.util.List;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

public class MainBottomSameCityAdapter extends BaseQuickAdapter<BottomSameCityBean, BaseViewHolder> implements LoadMoreModule {

    //设置图片圆角角度
    RoundedCorners roundedCorners = new RoundedCorners(10);
    //通过RequestOptions扩展功能,override:采样率,因为ImageView就这么大,可以压缩图片,降低内存消耗
    // RequestOptions options = RequestOptions.bitmapTransform(roundedCorners).override(300, 300);
    RequestOptions options = RequestOptions.bitmapTransform(roundedCorners);

    public MainBottomSameCityAdapter(int layoutResId, @Nullable List<BottomSameCityBean> data) {
        super(layoutResId, data);
        addChildClickViewIds(R.id.tv_send_msg);
    }


    @Override
    protected void convert(@NonNull BaseViewHolder helper, BottomSameCityBean item) {


        DrawableTextView tvAge = helper.getView(R.id.tv_age);
        DrawableTextView dtvOnlineStatus = helper.getView(R.id.dtv_onlineStatus);
        RelativeLayout rl_view = helper.getView(R.id.rl_view);
        ImageView ivAuth = helper.getView(R.id.iv_auth);

        LinearLayout ll_1 = helper.getView(R.id.ll_1);
//        LinearLayout ll_2 = helper.getView(R.id.ll_2);
        TextView tv_autograph = helper.getView(R.id.tv_autograph);
        DrawableTextView tv_gg = helper.getView(R.id.tv_gg);

        if(item.getIsgg().equals("CPM")){
            tv_gg.setBackground(getContext().getDrawable(R.drawable.shape_item_city_bg));
            tv_gg.setVisibility(View.VISIBLE);
            tv_gg.setText("广告");
            ll_1.setVisibility(View.GONE);
//            ll_2.setVisibility(View.GONE);
            dtvOnlineStatus.setVisibility(View.GONE);
            rl_view.setVisibility(View.GONE);
            tv_autograph.setText( item.getSignature());
            tv_autograph.setMaxLines(3);

        }else {
            tv_autograph.setText( item.getSignature());
            tv_autograph.setMaxLines(1);
            tv_gg.setVisibility(View.GONE);
            dtvOnlineStatus.setVisibility(View.VISIBLE);

            rl_view.setVisibility(View.VISIBLE);
            ll_1.setVisibility(View.VISIBLE);
//            ll_2.setVisibility(View.VISIBLE);
            tvAge.setVisibility(View.GONE);
//            if ("1".equals(item.getSex())) {
//                tvAge.setLeftDrawable(getContext().getDrawable(R.mipmap.gender_nan));
//                tvAge.setBackground(getContext().getDrawable(R.drawable.shape_item_city_bg));
//            } else {
//                tvAge.setLeftDrawable(getContext().getDrawable(R.mipmap.gender_nv));
//                tvAge.setBackground(getContext().getDrawable(R.drawable.shape_item_city_bg));
//            }

            helper.setText(R.id.tv_age, item.getAge());
        }


        helper.setGone(R.id.iv_gzuicon, StringUtil.isEmpty(item.getGzu_icon()))
                .setGone(R.id.iv_auth, (!"1".equals(item.getIsauth())))
                .setGone(R.id.iv_qua, StringUtil.isEmpty(item.getQua_icon()))
                .setGone(R.id.iv_levelicon, StringUtil.isEmpty(item.getLevel_icon()));

        //是否认证
        if ("1".equals(item.getIsauth())) {
            Glide.with(getContext()).load(item.getAuth_icon()).into((ImageView) helper.getView(R.id.iv_auth));
        }

        //设置贵族图标
        if (!"".equals(item.getGzu_icon())) {
            Glide.with(getContext()).load(item.getGzu_icon()).into((ImageView) helper.getView(R.id.iv_gzuicon));
        }
        //设置达人图标
        if (!"".equals(item.getLevel_icon())) {
            Glide.with(getContext()).load(item.getLevel_icon()).into((ImageView) helper.getView(R.id.iv_levelicon));
        }

        //设置优质图标
        if (!"".equals(item.getQua_icon())) {
            Glide.with(getContext()).load(item.getQua_icon()).into((ImageView) helper.getView(R.id.iv_qua));
        }




//        //是否开启语音
//        if ("1".equals(item.getIsvoice())) {
//            helper.getView(R.id.iv_voice).setVisibility(View.VISIBLE);
//        } else {
//            helper.getView(R.id.iv_voice).setVisibility(View.INVISIBLE);
//        }
//
//        //是否开启视频
//        if ("1".equals(item.getIsvideo())) {
//            helper.getView(R.id.iv_video).setVisibility(View.VISIBLE);
//        } else {
//            helper.getView(R.id.iv_video).setVisibility(View.INVISIBLE);
//        }

        //在线 接听 离线
        if ("在线".equals(item.getLast_online_time())) {
            dtvOnlineStatus.setLeftDrawable(getContext().getResources().getDrawable(R.drawable.bg_bottom_item1));
            dtvOnlineStatus.setTextColor(getContext().getResources().getColor(R.color.color_bottom_item1));
            dtvOnlineStatus.setText(item.getLast_online_time());
        } else if ("接听中".equals(item.getLast_online_time())) {
            dtvOnlineStatus.setLeftDrawable(getContext().getResources().getDrawable(R.drawable.bg_bottom_item2));
            dtvOnlineStatus.setTextColor(getContext().getResources().getColor(R.color.color_bottom_item2));
            dtvOnlineStatus.setText(item.getLast_online_time());
        } else {
            dtvOnlineStatus.setLeftDrawable(getContext().getResources().getDrawable(R.drawable.bg_bottom_item3));
            dtvOnlineStatus.setTextColor(getContext().getResources().getColor(R.color.color_bottom_item3));
            dtvOnlineStatus.setText(item.getLast_online_time());
        }


        Glide.with(getContext()).load(item.getAvatar())
                .apply(options)
                .centerCrop()
                .apply(new RequestOptions().transform(new CenterCrop(), new RoundedCorners(DpUtil.dp2px(10))))
                .into((ImageView) helper.getView(R.id.iv_anchor_photo));

        helper.setText(R.id.tv_name, item.getUser_nickname())
                .setText(R.id.tv_distance, item.getDistance())
                .setGone(R.id.tv_distance, StringUtil.isEmpty(item.getDistance()));
        if("".equals(item.getSignature())){
            helper.setText(R.id.tv_autograph,"这家伙很懒，什么都没留下");
        }



    }


}
